cmake_minimum_required(VERSION 3.5)

SET(CMAKE_C_COMPILER "/usr/bin/gcc")
SET(CMAKE_CXX_COMPILER "/usr/bin/g++")
add_definitions(-std=c++17)

project(sunnet)

set(MY_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/libs)

set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS_DEBUG "-g -DDEBUG")

# 设置编译结果输出路径
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -fPIC -fvisibility=default")

# 添加库文件路径
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rd/lua-5.4.7/src/)

include_directories(include)
include_directories(./3rd)

# aux_source_directory(./src DIR_SRCS)
set(SRC 
src/base_msg.cc 
src/conn_reader.cc 
src/conn_writer.cc 
src/conn.cc 
src/log_msg.cc 
src/log.cc 
src/lua_api.cc  
src/lua_log.cc 
src/packet_base.cc 
src/service_msg.cc 
src/service.cc 
src/socket_msg.cc 
src/socket_worker.cc 
src/sunnet.cc 
src/worker.cc)

add_library(sunnet ${SRC})
add_library(packetbase SHARED src/lua_packet.cc src/packet_base.cc src/log.cc)
add_executable(main src/main.cc)

# thread
find_package(Threads)
target_link_libraries(sunnet ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(packetbase ${CMAKE_THREAD_LIBS_INIT})

#Lua头文件、库
include_directories(./3rd/lua-5.4.7/src)
target_link_libraries(sunnet ${MY_LIB_PATH}/liblua.so dl)
target_link_libraries(main sunnet)
target_link_libraries(packetbase ${MY_LIB_PATH}/liblua.so)

#spdlog
include_directories(./3rd/spdlog)
target_link_libraries(sunnet ${MY_LIB_PATH}/libspdlog.so)
target_link_libraries(main sunnet)
target_link_libraries(packetbase ${MY_LIB_PATH}/libspdlog.so)

add_subdirectory(test)